<template>
	<view class="home">
		<view class="title">
			<view class="title-big">香哈菜谱大全</view>
			<view class="title-small">小白菜做菜必备烹饪助手</view>
		</view>
		<button>
			<image src="../../static/img/souuo.png"></image>共有857142道菜
		</button>
		<!-- 轮廓图 -->
		<view class="swiper-home">
			<swiper class="swiper" circular indicator-dots autoplay indicator-active-color="red">
				<swiper-item v-for="item in swiperiData" :key="item._id">
					<image :src="item.image_src"></image>
				</swiper-item>
			</swiper>
		</view>
		<!-- 菜单 -->
		<view class="foodsList">
			<view class="menu" v-for="item in menu" :key="item._id" @click="search(item.name)">
				<image :src="item.image_src"></image>
				<text>{{item.name}}</text>
			</view>
		</view>
		<!-- 楼层 -->
		<view class="floor">
			<view class="left" v-for="item in floordata" :key="_id" v-if="item.floor_imgs.length>1">
				<swiper class="left-item" circular indicator-dots autoplay indicator-active-color="red">
					<swiper-item v-for="element in item.floor_imgs" :key="item">
						<image :src="element"></image>
					</swiper-item>
				</swiper>
				<view class="floor-title">{{item.floor_title}}</view>
			</view>
			
			<view class="right">
				<view class="right-item" v-for="item in floordata" :key="_id" v-if="item.floor_imgs.length==1">
					<image :src="item.floor_imgs[0]"></image>
					<view class="floor-title">{{item.floor_title}}</view>
				</view>
				
			</view>
		</view>
		<!-- 推荐商品 -->
		<view class="recommend">
			<view class="recommend-item" v-for="item in recommend" :key="item._id">
				<view class="top">
					<image :src="item.coverpic"></image>
				</view>
				<h3>{{item.name}}</h3>
				<view class="bottom">
					<view class="left">
						<text>{{item.pageview}}</text>
						<image src="/static/img/liulam @2x.png"></image>
					</view>
					<view class="right">
						<text>{{item.collections}}</text>
						<image src="/static/img/soucang@2x.png" mode=""></image>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getSwipersApi,
		getFoodsListApi,getFloorDataApi,getRecommendDataApi
	} from "@/apis/index.js"


	export default {
		data() {
			return {
				swiperiData: [],
				menu:[],
				floordata:[],
				recommend:[]
			};
		},
		created() {
			this.getSwipers()
		},
		methods: {
			getSwipers() {
				getSwipersApi().then((res) => {

						this.swiperiData = res.message
					}),
					getFoodsListApi().then((res) => {
						
						this.menu=res.message
					}),
					getFloorDataApi().then((res)=>{
						
						this.floordata=res.message
					}),
					getRecommendDataApi().then((res)=>{
						console.log(res);
						this.recommend=res.message
					})
			},
			search(val){
				if(val=='甜点'){
					uni.navigateTo({
					    url:"/pages/search/search"
					})
				}else if(val=='分类')[
					uni.navigateTo({
					    url:"/pages/categorical/categorical"
					})
				]
			}
		}
	}
</script>

<style lang="scss" scoped>
	.title {
		width: 100%;
		height: 220rpx;
		background: url("../../static/img/ditu.png");
		background-size: cover;
		padding: 60rpx 0 0 32rpx;
		box-sizing: border-box;

		.title-big {
			color: white;
			font-size: 50rpx;
		}

		.title-small {
			color: white;
			font-size: 25rpx;
		}
	}

	button {
		width: 686rpx;
		height: 74rpx;
		border-radius: 20rpx;
		backgroundColor: "#fff";
		margin-top: -30rpx;
		font-size: 28rpx;
		color: gray;

		image {
			width: 26rpx;
			height: 26rpx;
			margin-right: 10rpx;
		}
	}

	.swiper-home {
		padding: 20rpx;
		box-sizing: border-box;

		.swiper image {
			width: 100%;
			height: 100%;
		}
	}
	.foodsList{
		display: grid;
		grid-template-columns: repeat(5,1fr);
		gap: 10rpx;
	.menu{
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		
		image{
			width: 60rpx;
			height: 60rpx;
		}
	}
	}
	.floor{
		display: grid;
		grid-template-columns: repeat(2,1fr);
		padding: 20rpx;
		box-sizing: border-box;
		.left{
			width: 330rpx;
			height: 360rpx;
			position: relative;
			.left-item{
				width: 100%;
				height: 100%;
				image{
					width: 100%;
					height: 100%;
				}
			}
			.floor-title{
					width: 164rpx;
					height: 60rpx;
					background-color: #d86f32;
					opacity: 0.63;
					border-radius: 8rpx;
					font-size: 26rpx;
					text-align: center;
					line-height:60rpx ;
					color: white;
					position: absolute;
					top: 12rpx;
					left: 12rpx;
			}
			
		}
		.right{
			width: 330rpx;
			height: 360rpx;
			display: flex;
			flex-direction: column;
			.right-item{
				width: 100%;
				height: 176rpx;
				margin-bottom: 10rpx;
				position: relative;
				image{
					width: 100%;
					height: 100%;
				}
				.floor-title{
						width: 164rpx;
						height: 60rpx;
						background-color: #d86f32;
						opacity: 0.63;
						border-radius: 8rpx;
						font-size: 26rpx;
						text-align: center;
						line-height:60rpx ;
						color: white;
						position: absolute;
						top: 12rpx;
						left: 12rpx;
				}
			}
			
		}
	}
	.recommend{
		display: grid;
		grid-template-columns: repeat(2,1fr);
		gap: 10rpx;
		padding: 20rpx;
		box-sizing: border-box;
		.recommend-item{
			.top{
				width: 100%;
				image{
					width: 100%;
				}
			}
			.bottom{
				display: flex;
				.left{
					text{
						font-size: 28rpx;
						color: gray;
					}
					image{
						width: 34rpx;
						height: 28rpx;
						vertical-align: middle;
					}
				}
				.right{
					text{
						font-size: 28rpx;
						color: gray;
					}
					image{
						width: 34rpx;
						height: 28rpx;
						vertical-align: middle;
					}
				}
			}
		}
	}
</style>
